import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static int MAX_CAPACITY = 20_0001;

    public static int[] father = new int[MAX_CAPACITY];

    public static int[] size = new int[MAX_CAPACITY];

    public static int[] stack = new int[MAX_CAPACITY];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        // 读取 n 和 m
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        // -根据数组大小重新设定，可以降低空间复杂度
        MAX_CAPACITY = n+1;
        initialize();

        // 处理 m 个操作
        for (int i = 0; i < m; i++) {
            st = new StringTokenizer(br.readLine());
            int z = Integer.parseInt(st.nextToken());
            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());
            if (z == 1) {
                union(x, y);
            } else {
                System.out.println(isSameSet(x, y) ? "Y" : "N");
            }
        }
    }

    public static void initialize() {
        /**
         * 初始化*/
        // -所有元素初始指向自己，且集合大小为1
        for(int i = 0; i < MAX_CAPACITY; i++) {
            father[i] = i;
            size[i] = 1;
        }
    }

    public static int find(int a) {
        /**
         * 查找a元素所在集合的代表元素并做扁平化*/
        // 1 查找代表元素
        int i = 0;
        while(a != father[a]) {
            stack[i++] = a;
            a = father[a];
        }

        // 2 将途径元素全部指向代表元素
        while(i > 0) {
            father[stack[--i]] = a;
        }

        // 3 返回值
        return a;
    }

    public static boolean isSameSet(int a, int b) {
        /**
         * 判断a、b是否在同一集合中*/
        return find(a) == find(b);
    }

    public static void union(int a, int b) {
        /**
         * 合并a、b所在集合*/
        // 1 找到a、b所有集合代表元素
        int fa = find(a);
        int fb = find(b);

        // 2 若是一个集合则不合并，否则合并
        if(fa != fb) {
            if(size[fa] >= size[fb]) {
                size[fa] += size[fb];
                father[fb] = fa;
            } else {
                size[fb] += size[fa];
                father[fa] = fb;
            }
        }
    }
}
